function addLessonClick(day, timetableId){
    $('#add_lesson'+timetableId).modal({show:true});
    document.getElementById('modal_small'+timetableId).innerHTML = day;
    setupAddSubjectLesson(day, timetableId);
    send_mutex = 1;
    $("#add_SubjectLesson"+timetableId).click( function(){
        if (send_mutex == 1){
            send_mutex = 0;
            $.ajaxSetup({
                headers: { "X-CSRFToken":  $.cookie('csrftoken') }
            });
            if($('.addSubjectLesson_' + timetableId + ' #professorChoice option:selected').val() != 0){
                professorChoice = $('.addSubjectLesson_' + timetableId + ' #professorChoice option:selected').text();
                $professorChoiceInput = $('<input type="text" id="professorChoiceInput" name="professorChoice"/>').val(professorChoice).hide();
                $('.addSubjectLesson_' + timetableId).append($professorChoiceInput);
                subjectChoice = $('.addSubjectLesson_' + timetableId + ' #subjectChoice option:selected').text();
                $subjectChoiceInput = $('<input type="text" id="subjectChoiceInput" name="subjectChoice"/>').val(subjectChoice).hide();
                $('.addSubjectLesson_' + timetableId).append($subjectChoiceInput);
            }
            var request = $.ajax({
                data: $('.addSubjectLesson_' + timetableId).serialize(),
                url: "/account/addSubjectLesson/",
                type: "POST",
                dataType: 'json'
            }).done(function(response){
                if (response.success == 'False'){
                    $('.addSubjectLesson_' + timetableId).html(response.html);
                    if (response.choice == 'True'){
                        $('.addSubjectLesson_' + timetableId + ' #collapseOne').removeClass('in');
                        $('.addSubjectLesson_' + timetableId + ' #collapseTwo').addClass('in');
                    }
                    setupAddSubjectLesson(day, timetableId);
                    send_mutex = 1;
                }
                else if (response.success == 'True'){
                    $('#add_lesson'+timetableId).modal('hide').on('hidden', function () {
                        location.reload();
                        send_mutex = 1; //nötig?
                    })
                }
            });
        }
    });
}

function setupAddSubjectLesson(day, timetableId){
    $('#id_les_day_'+timetableId).val(day);
    $('#id_timetable_'+timetableId).val(timetableId);
    $('select#subjectChoice').hide();
    $.getJSON('/account/getProfessor/' + timetableId, function(j){
        var options = '';
        for (var i = 0; i < j.length; i++) {
            options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
        }
        $("select#professorChoice").html(options);
    });
    $("select#professorChoice").change(function(){
        $.getJSON('/account/getSubject/' + timetableId + '/' + $('#professorChoice option:selected').text(), function(j){
            var options = '';
            for (var i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
            }
            $("select#subjectChoice").html(options).show();
        })
    })
}

function editLesson(id){
    $('#edit_lesson').modal({show:true});
    document.getElementById('modal_small').innerHTML = day;
    $("#les_day").val(day);
}

function addLessonHover(day){
    document.getElementById(day).style.backgroundColor= "#eeeeee";
}

function addLessonOut(day){
    document.getElementById(day).style.backgroundColor = "white";
}


/*hovereffekt edit and delete lesson*/
$(document).ready(function () {
    $('#extras_lesson a i').hover(function () {
        $(this).addClass('icon-white');
    }, function () {
        $(this).removeClass('icon-white');
    });

});

function lessonHover(id){
    var extras_lesson = document.getElementById(id ,'extras_lesson');
    var a = extras_lesson.getElementsByTagName('a');
    a[0].style.display='block';
    a[1].style.display='block';
}

function lessonOut(id){
    var extras_lesson = document.getElementById(id ,'extras_lesson');
    var a = extras_lesson.getElementsByTagName('a');
    a[0].style.display='none';
    a[1].style.display='none';
}

